package com.dgw.bootuserservice.service.impl;


import com.mall.bean.UserAddress;
import com.mall.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;


@Service(interfaceClass = UserService.class)
public class UserServiceImpl implements UserService {

	public UserServiceImpl() { }

	@HystrixCommand(commandProperties = {
	        /**  10米内请求10次 将会触发短路条件    */
			@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
            /**  隔离线程的超时时间为2s */
			@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000") })
	@Override
	public List<UserAddress> getUserAddressList(String userId) {
		System.out.println("UserServiceImpl.....old...");
		// TODO Auto-generated method stub
		UserAddress address1 = new UserAddress(1, "北京市昌平区宏福科技园综合楼3层", "1", "李老师", "010-56253825", "Y");
		UserAddress address2 = new UserAddress(2, "深圳市宝安区西部硅谷大厦B座3层（深圳分校）", "1", "王老师", "010-56253825", "N");
		/*try {
			Thread.sleep(4000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		if(Math.random() > 0.5){
			throw new RuntimeException("UserService 出现异常");
		}
		return Arrays.asList(address1,address2);
	}
}
